<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library"
  exclude-result-prefixes="msxml umbraco.library"
  xmlns:fb="http://www.facebook.com/2008/fbml">

  <xsl:output method="html" omit-xml-declaration="yes"/>
  <xsl:param name="currentPage"/>
  <xsl:param name="MaxNoChars" select="300" />


  <xsl:variable name="recordsPerPage" select="30"/>
  <xsl:variable name="pageNumber">
    <xsl:choose>
      <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="numberOfRecords" select="count($currentPage/*[@isDoc and string(./umbracoNaviHide) != '1'])"/>

  <xsl:template match="/">

    <div class="ArticleList2Col">
      <!--
      =============================================================
      For Each child node of the currentpage
      =============================================================
      -->
      <ul class="editorsDesk-list clearfloat">
        <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
            <li>
              <h4>
                <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
                  <xsl:value-of select="@nodeName" />
                </a>
              </h4>
              <p class="postDate">
                <xsl:value-of select="concat('Published : ', umbraco.library:FormatDateTime(@createDate, 'dd.MM.yy'))" />
              </p>
              <div class="editorsDeskImg">
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <img class="ArticleImage" src="{current()/articlePhoto}" alt="{@nodeName}"/>
                </a>
              </div>
              <div class="editorsDeskText">
                <p>
                  <!-- TODO: strip HTML & truncate -->
                  <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(current()/bodyText), $MaxNoChars, '...')" />
                  <a href="{umbraco.library:NiceUrl(@id)}" class="more-link">
                    (More ...)
                  </a>
                  <br />
                </p>
                <img src="/umbraco/images/JE/facebooklike.PNK" alt="" />
                <div id="fb-root">
                </div>
                <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
                <fb:like href="{umbraco.library:NiceUrl(@id)}" send="false" layout="button_count"
                    width="150" show_faces="false" font="arial">
                </fb:like>
              </div>
            </li>
          </xsl:if>
        </xsl:for-each>
      </ul>

      <div class="clear EditorPaging">
        <div class="alignleft">
          <xsl:choose>
            <xsl:when test="$pageNumber &gt; 1">
              <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber - 1}">Previous</a>
            </xsl:when>
            <xsl:otherwise>
              <span>Previous</span>
            </xsl:otherwise>
          </xsl:choose>
        </div>

        <div class="alignleft">
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i">1</xsl:with-param>
            <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
            <xsl:with-param name="count" select="ceiling(count($currentPage/*[@isDoc and string(./umbracoNaviHide) != '1']) div $recordsPerPage)"></xsl:with-param>
          </xsl:call-template>
        </div>
        <div class="alignright">
          <xsl:choose>
            <xsl:when  test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
              <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber + 1}">Next</a>
            </xsl:when>
            <xsl:otherwise>
              <span>Next</span>
            </xsl:otherwise>
          </xsl:choose>
        </div>

      </div>

    </div>

  </xsl:template>

  <xsl:template name="for.loop">
    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i &lt;= $count">
      <xsl:if test="$page != $i">
        <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$i}" >
          <xsl:value-of select="$i" />
        </a>
      </xsl:if>
      <xsl:if test="$page = $i">
        <span>
          <xsl:value-of select="$i" />
        </span>
      </xsl:if>
    </xsl:if>
    <xsl:if test="$i &lt;= $count">
      <xsl:call-template name="for.loop">
        <xsl:with-param name="i">
          <xsl:value-of select="$i + 1"/>
        </xsl:with-param>
        <xsl:with-param name="count">
          <xsl:value-of select="$count"/>
        </xsl:with-param>
        <xsl:with-param name="page">
          <xsl:value-of select="$page"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>